package com.opgea.crm.services;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.opgea.crm.common.vo.ContactVo;
import com.opgea.crm.domain.entities.AdditionalContact;
import com.opgea.crm.domain.modal.QualifierModel;
import com.opgea.crm.repository.AdditionalContactRepo;

@Service
public class AdditionalContactServiceImpl implements AdditionalContactService{

	@Autowired
	AdditionalContactRepo contactRepo;
	
	
	public void create(AdditionalContact addtionalContact) {
		contactRepo.create(addtionalContact);
	}

	public void remove(long contactId) {
		contactRepo.remove(contactId);
	}

	public AdditionalContact find(long contactId) {
		return contactRepo.find(contactId);
	}

	public List<ContactVo> findAll() {
		System.out.println("LeadServiceImpl >> findAllContacts");
		List<ContactVo> list=new ArrayList<ContactVo>();
		List<AdditionalContact> contactList = contactRepo.findAll();
    	for(AdditionalContact data: contactList)
    	{
    		ContactVo contactVo = new ContactVo();
    		contactVo.setId(data.getId());
    		contactVo.setFirstName(data.getFirstName());
    		contactVo.setLastName(data.getLastName());
    		contactVo.setTitle(data.getTitle());
    		contactVo.setEmail(data.getEmail());
    		contactVo.setWorkPhone(data.getWorkPhone()); 
    		contactVo.setHomePhone(data.getHomePhone());
    		contactVo.setMobileNo(data.getMobileNo());
    		contactVo.setFax(data.getFax());
    		System.out.println("Contact : "+contactVo);
    		list.add(contactVo);
    	}
    	return list;
	}

	public List<ContactVo> findAllByLeadId(long leadId) {
		System.out.println("LeadServiceImpl >> findAllContacts");
		List<ContactVo> list=new ArrayList<ContactVo>();
		List<AdditionalContact> contactList = contactRepo.findAllByLeadId(leadId);
    	for(AdditionalContact data: contactList)
    	{
    		ContactVo contactVo = new ContactVo();
    		contactVo.setId(data.getId());
    		contactVo.setFirstName(data.getFirstName());
    		contactVo.setLastName(data.getLastName());
    		contactVo.setTitle(data.getTitle());
    		contactVo.setEmail(data.getEmail());
    		contactVo.setWorkPhone(data.getWorkPhone()); 
    		contactVo.setHomePhone(data.getHomePhone());
    		contactVo.setMobileNo(data.getMobileNo());
    		contactVo.setFax(data.getFax());
    		System.out.println("Contact : "+contactVo);
    		list.add(contactVo);
    	}
    	return list;
	}
	
	public List<QualifierModel> findAllContactNameByLeadId(long leadId) {
		System.out.println("LeadServiceImpl >> findAllContacts");
		List<QualifierModel> list=new ArrayList<QualifierModel>();
		List<AdditionalContact> contactList = contactRepo.findAllByLeadId(leadId);

    	for(AdditionalContact data: contactList)
    	{
    		
    		QualifierModel qualifier = new QualifierModel(data.getId(), data.getFirstName());
    		list.add(qualifier);
    	}
    	return list;
	}

}
